package person.bangbang.im.Androidgin.UI;

import java.util.List;

import person.bangbang.im.Androidgin.R;
import person.bangbang.im.Androidgin.Framework.ProtocolSpec;
import person.bangbang.im.Androidgin.Framework.StatusType;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * a adapter for protocol spinner.
 *
 */
public class StatusAdapter extends ArrayAdapter<StatusType> {
		// defaoult statustype res;
		private static final int ICON_DEFAULT = -1;
		private int res; // not use now

		public StatusAdapter(Context context, int textViewResourceId,
				List<StatusType> objects) {
				super(context, textViewResourceId, objects);
				res = textViewResourceId;
			}

		
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			StatusType s = getItem(position);
				 LinearLayout l;
	 
				 if (null == convertView) {
					 l = new LinearLayout(getContext());
					 LayoutInflater inflate = (LayoutInflater) (getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE));
					 inflate.inflate(R.layout.status_spinner_item, l, true);
				 } else {
					 l = (LinearLayout) convertView;
				 }
			    ImageView iconView = (ImageView)l.findViewById(R.id.status_icon);
			    TextView idView = (TextView)l.findViewById(R.id.status_id);
			      
			    int res =  getItem(position).getResId();
			    if (res != StatusType.RES_NONE) {
			    	iconView.setImageResource(res );
			    } else {
			    	// default.
			    	iconView.setImageResource(StatusType.RES_ONLINE);
			    }
			    idView.setText(getItem(position).getName());
				    
				return l;    
		}
		@Override
		public View getDropDownView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
			return getView(position, convertView, parent);
		}
}
